export default (url, data, method = "GET", contentType = 1) => {
	return new Promise((resolve, reject) => {
		let header = {
			'content-type': contentType === 1 ? 'application/json' : 'application/x-www-form-urlencoded'
		}
		let baseUrl = "http://localhost:3000";
		uni.request({
			url: baseUrl + url,
			data,
			method,
			header: {
				cookie: uni.getStorageSync('cookies')? uni.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1): ''
			},
			header,
			withCredentials: true,
			success: (res) => {
				// console.log(res)
				if (res.statusCode === 200) {
					//请求成功
					uni.setStorage({
					    key: 'cookies',
					    data: res.cookie
					})
					resolve(res.data);
				} else {
					uni.showToast({
						icon: 'none',
						title: "请求错误：" + res.statusCode,
						duration: 1500
					});
				}
			},
			fail: (err) => {
				console.log("err:", err)
				uni.showToast({
					icon: 'none',
					title: err.errMsg,
					duration: 1500
				});
				reject(err);
			}
		})
	})
}
